package com.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class RequestAPIServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //getRequestURI()	获取请求的资源路径
        System.out.println("URI =>"+req.getRequestURI());//URI =>/webTest02/req
        //getRequestURL()	获取请求的统一资源定位符（绝对路径）
        System.out.println("URI =>"+req.getRequestURL());//URI =>http://localhost:8080/webTest02/req
        //getRemoteHost()	获取客户端的 ip 地址
            //在IDEA中，使用localhost访问时，得到的客户端ip地址是 0:0:0:0:0:0:0:1
            //在IDEA中，使用127.0.0.1访问时，得到的客户端ip地址是 127.0.0.1
        System.out.println("客户端ip地址 =>"+req.getRemoteHost());//客户端ip地址 =>0:0:0:0:0:0:0:1
        //getHeader()	获取请求头
        System.out.println("请求头User-Agent =>"+req.getHeader("User-Agent"));
        //请求头User-Agent =>Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36

        //getMethod()	获取请求的方式 GET 或 POST
        System.out.println("请求的方式 =>"+req.getMethod());//请求的方式 =>GET
    }
}
